package com.ea.eadp.nexus.test.pageDefinition.mobile;

import com.ea.eadp.nexus.test.common.PageOperation;
import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;


public class LoginPage extends MobileBasePage {
    public final static String loginPage = "loginPage";
    public static final String emailInputBox = "login-email";
    public static final String passwordInputBox = "login-password";

    public LoginPage(WebDriver driver) {
        super(driver, LoginPage.class, loginPage);
    }

    public void navigate(String uri) {
        driver.switchTo().window(operationWindowHandle);
        log.info(uri);
        driver.navigate().to(uri);
    }

    public void login() {
        log.info("Login");
        driver.findElement(By.xpath("//div[@id='loginBtn']/div[1]/input")).click();
    }

    public void reset() {
        log.info("Reset Password Page");
        driver.findElement(By.xpath("//div[@id='reset-link']/a")).click();
    }

    public void signUp() {
        log.info("Sign Up Page");
        driver.findElement(By.xpath("//div[@id='signupBtn-Short']/a")).click();
    }
	public void signUpMobile() {
		log.info("Sign Up Page");
		driver.findElement(By.xpath(".//*[@id='signupBtn-Short']/a/span/span")).click();
	}

    public void enterEmail(String email) {
        log.info("Enter Email:" + email);
        PageOperation.SendKeyToElementAfterWait(driver,emailInputBox, email);
    }

    public void validateEmail(String email, String errorMessage) {
        log.info("Validate Email:" + email);
        sendInput(emailInputBox, email);
        clickBlank("//div[@id='loginPage']/div[1]/h1");
        Assert.assertEquals(getEmailInvalidError(), errorMessage, "Input not trigger the correct error message");
    }

    public void enterPassword(String password) {
        log.info("Enter Password:" + password);
        PageOperation.SendKeyToElementAfterWait(driver,passwordInputBox, password);
    }

    public void validatePassword(String password, String errorMessage) {
        log.info("Validate Password:" + password);
        sendInput(passwordInputBox, password);
        driver.findElement(By.xpath("//div[@id='loginBtn']/div[1]/input")).click();
        TestUtil.sleep(1);
        Assert.assertEquals(getPasswordInvalidError(), errorMessage, "Input not trigger the correct error message");
    }

    public void closePopupErrorLoginButton() {
        driver.findElement(By.xpath("//div[@id='login-popup']/div[1]/h1[1]/span[1]")).click();
    }

    public String getEmailInvalidError() {
        return getElementStringByXPath("//form[@id='loginForm']/div[1]/div[1]/span[2]");
    }

    public String getPasswordInvalidError() {
        return getElementStringByXPath("//div[@id='login-popup']/div[2]/div[1]");
    }

    public String getLoginResponse() {
        TestUtil.sleep(1);
        return getElementStringByXPath("//div[@id='login-popup']/div[2]/div[1]");
    }


	public String getMobileGameSignupPageFooter(int index){
		return getElementStringByXPath(".//*[@id='loginPage']/div[3]/ul/li["+index+"]/a");
	}



	public String getMobileGameUpgradePageFooter(int index){
		return getElementStringByXPath(".//*[@id='upgradePage']/div[3]/ul/li["+index+"]/a");
	}



	public String getMobileGameCreatePageFooter(int index){
		return getElementStringByXPath(".//*[@id='createPage']/div[3]/ul/li["+index+"]/a");

	}



	public String getResetPasswordPageFooter(int index){
		return getElementStringByXPath(".//*[@id='resetPasswordPage']/div[3]/ul/li["+index+"]/a");
	}
}